﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Rhizome.Contract;
using Rhizome.Contract.Diag;
using Rhizome.Model.Validation;

namespace Rhizome.Model
{
	public sealed class Transition : TransitionBase, IValidate, IStatesDiag
	{
		public Transition(object @event, IAction action, object state) : base(@event, action)
		{
			if (state == null) throw new ArgumentNullException("state");
			State = state;
		}

		public Transition(object @event, object state) : this(@event, null, state)
		{
		}

		public Transition()
		{
		}

		public object State { get; set; }

		#region IStatesDiag Members

		IEnumerable<object> IStatesDiag.StateIds
		{
			[DebuggerStepThrough]
			get { yield return State; }
		}

		#endregion

		#region IValidate Members

		IEnumerable<IValidationResult> IValidate.GetValidationResults()
		{
			if (State == null) yield return ValidationResult.StateNotSet;
		}

		#endregion

		public override object GetTransitionState()
		{
			return State;
		}

		public override string ToString()
		{
			return string.Format("Event: {0}, State: {1}", Event, State);
		}
	}
}